package org.simple.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @author jihu
 * date 2022-09-23
 */
@EnableOpenApi
@Configuration
public class SwaggerConfig {

    @Value("${spring.application.name}")
    private String serverName;

    @Bean
    public Docket createRestApi() {
        //swagger设置，基本信息，要解析的接口及路径等
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("org.simple"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 生成接口信息，包括标题、联系人，联系方式等
     **/
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("基础框架-"+serverName+"服务接口文档")
                .description(null)
                .contact(new Contact("jihu", "", "springhuge@foxmail.com"))
                .version("1.0")
                .build();
    }
}
